﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TextSpawner : MonoBehaviour
{
    private const float RandomOffset = 1f;
    private const float SpawnInterval = 0.1f;

    public int SpawnNum = 10;
    private int mCurrentSpawnNum;

    public SpriteRenderer PictureRenderer;

    private IEnumerator Start()
    {
        GameManager.GetInstance().GameStart();
        PictureRenderer.sprite = PictureLogicScript.sGetInstance().GetSprite();
        PictureRenderer.size = new Vector2(2f, 2f);
        mCurrentSpawnNum = 0;
        while (mCurrentSpawnNum < SpawnNum)
        {
            if (Random.Range(0f, 1f) < 0.5f)
            {
                GameObject text = GameObject.Instantiate(Resources.Load("Text")) as GameObject;
                text.transform.position = transform.position + Vector3.right * Random.Range(-RandomOffset, RandomOffset);
                GameManager.GetInstance().AddText(text.GetComponent<TextScript>());
            }
            else
            {
                GameObject text = GameObject.Instantiate(Resources.Load("Text1")) as GameObject;
                text.transform.position = transform.position + Vector3.right * Random.Range(-RandomOffset, RandomOffset);
                GameManager.GetInstance().AddText(text.GetComponent<TextScript>());
            }
            mCurrentSpawnNum++;
            PictureRenderer.size = new Vector2(2f, 2f - (float)mCurrentSpawnNum / SpawnNum * 2f);
            yield return new WaitForSeconds(SpawnInterval);
        }
    }
}
